var path = require("path");
var express = require("express");
var proxyMiddleware = require("http-proxy-middleware");

// var proxyMiddleware = require('proxy-middleware');
var app = express();

require("./API/config.js");
app.use(express.static(path.join(__dirname, "/dist/")));
var proxyTable = {
  "/api": {
    target: global.httpStr + global.loginIp + ":" + global.loginport,
    changeOrigin: true
  }
};

Object.keys(proxyTable).forEach(function (context) {
  var options = proxyTable[context];
  if (typeof options === "string") {
    options = {
      target: options
    };
  }
  app.use(proxyMiddleware(context, options));
});

app.listen(9004, function (err) {
  if (err) {
    console.log(err);
    return;
  }
  console.log("server start 9004");
});
